package com.equipmentRent.system.service.impl;

import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import com.equipmentRent.system.domain.VO.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.equipmentRent.system.mapper.OrderMapper;
import com.equipmentRent.system.domain.Order;
import com.equipmentRent.system.service.IOrderService;
import com.equipmentRent.common.core.text.Convert;

/**
 * 主订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-17
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements IOrderService

{
    @Autowired
    private OrderMapper orderMapper;

    /**
     * 查询主订单
     * 
     * @param id 主订单主键
     * @return 主订单
     */
    @Override
    public Order selectOrderById(String id)
    {
        return orderMapper.selectOrderById(id);
    }

    /**
     * 查询主订单列表
     * 
     * @param order 主订单
     * @return 主订单
     */
    @Override
    public List<Order> selectOrderList(Order order)
    {
        return orderMapper.selectOrderList(order);
    }


    @Override
    public List<OrderVo> selectOrderVoList(Order order)
    {
        return orderMapper.selectOrderVoList(order);
    }

    /**
     * 新增主订单
     * 
     * @param order 主订单
     * @return 结果
     */
    @Override
    public int insertOrder(Order order)
    {
        return orderMapper.insertOrder(order);
    }

    /**
     * 修改主订单
     * 
     * @param order 主订单
     * @return 结果
     */
    @Override
    public int updateOrder(Order order)
    {
        return orderMapper.updateOrder(order);
    }

    /**
     * 批量删除主订单
     * 
     * @param ids 需要删除的主订单主键
     * @return 结果
     */
    @Override
    public int deleteOrderByIds(String ids)
    {
        return orderMapper.deleteOrderByIds(Convert.toStrArray(ids));
    }

    /**
     * 批量软删除主订单
     *
     * @param ids 需要软删除的主订单主键
     * @return 结果
     */
    @Override
    public int softDeleteOrderByIds(String ids)
    {
        String[] strArray = Convert.toStrArray(ids);
        int count = 0;
        for (String s : strArray) {
            Order order = orderMapper.selectOrderById(s);
            int i = orderMapper.update(null, Wrappers.<Order>lambdaUpdate()
                    .set(Order::getIsDelete, 1L)
                    .eq(Order::getId, order.getId()));
            count = count + i;
        }
        return count;
    }

    /**
     * 删除主订单信息
     * 
     * @param id 主订单主键
     * @return 结果
     */
    @Override
    public int deleteOrderById(String id)
    {
        return orderMapper.deleteOrderById(id);
    }
}
